package me.ilich.piet.programs;

import java.io.InputStream;

import me.ilich.piet.interpreter.JPietInterpreter;
import me.ilich.piet.interpreter.JPietInterpreter.InterpreterException;
import me.ilich.piet.interpreter.Stack;
import junit.framework.TestCase;

public class InterpretetTestCase extends TestCase {
	
	private JPietInterpreter mInterpreter;
	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		mInterpreter = new JPietInterpreter();
	}
	
	public void testHelloWorld(){
		final StringBuilder sb = new StringBuilder();
		mInterpreter.setOutListener(new Stack.OnOutListener() {
			
			@Override
			public void onOut(int i) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onOut(char c) {
				sb.append(c);
			}
		});
		
		InputStream stream = getClass().getResourceAsStream("Piet_hello.png");		
		try {
			mInterpreter.run(stream);
		} catch (InterpreterException e) {
			fail(e.getMessage());
		}
		
		assertEquals("Hello world!", sb.toString());
	}

}
